package com.crmweb.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.crmweb.entity.Netfollows;
import com.crmweb.entity.PageVo;
import com.crmweb.entity.Result;
import com.crmweb.entity.Users;
import com.crmweb.service.NetfollowsService;
import com.crmweb.tool.ConstantUtil;

@RestController
public class NetfollowsController {

	@Resource
	private NetfollowsService nfs;
	@RequestMapping("netFile/addNetfolliws")
	public Object addNetfolliws(Netfollows netfs,HttpServletRequest request) {
		HttpSession session = request.getSession();
		Users user = (Users) session.getAttribute(ConstantUtil.USERS); 
		String userId = user.getId();
		netfs.setUserId(userId);
		int i = nfs.addNetfolliws(netfs);
		if(i>0) {
			Result res = new Result("添加跟踪信息成功","",true);
			return res;
		}else {
			Result res = new Result("添加跟踪信息失败","",false);
			return res;
		}
		
	}
	// 查看该学生的所有跟踪信息
	@RequestMapping("netFile/selNetfBysid")
	public Map<String, Object> selNetfBysid(int stuid) {
		List<Netfollows> list = nfs.selNetfBysid(stuid);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("data", list);
		map.put("count", list.size());
		return map;
		
	}
	/**
	 * 查询所有跟踪者
	 * @return
	 */
	@RequestMapping("netFile/selUsersByUid")
	public Object selUsers(){
		List<String> uid = nfs.selAllNetfollow();
		List<Users> list = nfs.selUsersByUid(uid);
		
//		Map<String, Object> map = new HashMap<>();
//		map.put("ss", list);
		return list;
		
	}
	@RequestMapping("netFile/showAllByWhere")
	public Map<String, Object> showAllByWhere(HttpServletRequest request,Netfollows nff){
		
		String page = request.getParameter("page");
		String pageSize = request.getParameter("limit");
		PageVo vo = new PageVo();
		vo.setPage(Integer.parseInt(page));
		vo.setPageSize(Integer.parseInt(pageSize));
		
		System.out.println("------------------"+nff.getUserId());
		nff.setVo(vo);
		List<Netfollows> list = nfs.showAllByWhere(nff);
		Map<String, Object> map = new HashMap<>();
		map.put("code", 0);
		map.put("data", list);
		map.put("count", nfs.getcountBywhere(nff));
		
		return map;
		
	}
	
}
